home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / contrib / multimedia / rec.sparc < prev    next >
Text File  |  1993-03-16  |  2KB  |  122 lines

  1. #!/usr/bin/perl
  2. #
  3. # rec - record audio data with prompting
  4. #
  5. # Usage: rec [-help] [-(no)pause] [file]
  6. #
  7. # Author: Jerry Sweet <jsweet@irvine.com>
  8. #
  9. # $Header: /sparc/users/jsweet/notes/mime/tutorial/rec.sparc,v 1.2 1993/03/17 00:45:05 jsweet Exp $
  10.  
  11. #
  12. # Subprograms
  13. #
  14.  
  15. sub barf {
  16.   print STDERR "$prog: ", @_, "\n";
  17.   exit 1;
  18. }
  19.  
  20.  
  21. sub endit {
  22.   # Come here on a TERM (^C) signal.
  23.  
  24.   if ($child_pid) {
  25.     kill 15, $child_pid;
  26.     wait;
  27.   }
  28.  
  29.   if ($file) {
  30.     close(STDOUT);
  31.     close(OUT);
  32.   }
  33.  
  34.   exit 0;
  35. }
  36.  
  37. #
  38. # Main
  39. #
  40.  
  41.  
  42. ($prog = $0) =~ s|.*/||;
  43.  
  44. $pause = 1;
  45.  
  46. while ($_ = shift @ARGV) {
  47.   /^-help$/ && do {
  48.       print STDERR <<"xxEndHelpxx";
  49. $prog - record audio data with prompting
  50. Usage: $prog [-help] [-(no)pause] [file]
  51. Options:
  52.   -help       print this help message
  53.   -nopause    don't prompt; just do it
  54.   -pause      prompt and wait for Return [default]
  55. xxEndHelpxx
  56.  
  57.       exit 1;
  58.     };
  59.  
  60.   /^-nopause$/ && do { --$pause; next; };
  61.   /^-pause$/ && do { ++$pause; next; };
  62.  
  63.   /^[^\-]/ && do { $file = $_; next; };
  64.  
  65.   &barf("unrecognized command line option \"$_\"");
  66. }
  67.  
  68. $pause = $pause > 0;
  69.  
  70. select(STDERR);
  71. $| = 1;    # make stderr unbuffered.
  72. select(STDOUT);
  73.  
  74. @rec_args = ('record');
  75.  
  76. if ($file) {
  77.   open(OUT, ">$file") || &barf("can't create \"$file\" - $!");
  78.   open(STDOUT, ">&OUT") || &barf("can't dup stdout to \"$file\" - $!");
  79. }
  80. else {
  81.   if (-t STDOUT) {
  82.     &barf("you need to specify a file or redirect stdout");
  83.   }
  84. }
  85.  
  86. if (! $pause) {
  87.   $SIG{'TERM'} = 'endit';
  88.   exec "@rec_args";
  89.   &barf("exec of \"@rec_args\" failed");
  90. }
  91.  
  92. print STDERR "Press Return to start...";
  93. $wait = <STDIN>;
  94.  
  95. $child_pid = fork;
  96.  
  97. if ($child_pid == 0) {
  98.   # We're in the child.
  99.   exec "@rec_args";
  100.   &barf("(in child) exec of \"@rec_args\" failed");
  101. }
  102. else {
  103.   if ($child_pid < 0) {
  104.     # Fork failed.
  105.     &barf("problem forking - $!");
  106.   }
  107.   else {
  108.     # We're in the parent.
  109.     print STDERR "Press Return to end...";
  110.     $wait = <STDIN>;
  111.     kill 15, $child_pid;
  112.     wait;
  113.   }
  114. }
  115.  
  116. if ($file) {
  117.   close(STDOUT);
  118.   close(OUT);
  119. }
  120.  
  121. exit 0;
  122.